unit frmWebBroser;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, Buttons, ExtCtrls, SHDocVw, StdCtrls, MShare, Winapi.ActiveX,
  dxGDIPlusClasses, RzBmpBtn;

type
  TfrmWebBrowser = class(TForm)
    Panel1: TPanel;
    sbtnWebBrowserClose: TSpeedButton;
    WebBrowser: TWebBrowser;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Image1: TImage;
    RzBmpButton1: TRzBmpButton;
    procedure FormCreate(Sender: TObject);
    procedure WebBrowserWindowClosing(ASender: TObject; IsChildWindow: WordBool; var Cancel: WordBool);
    procedure sbtnWebBrowserCloseClick(Sender: TObject);
    procedure WebBrowserNewWindow2(ASender: TObject; var ppDisp: IDispatch; var Cancel: WordBool);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure RzBmpButton1Click(Sender: TObject);
    procedure WebBrowserDocumentComplete(ASender: TObject;
      const pDisp: IDispatch; const URL: OleVariant);
  private
    { Private declarations }
  public
    procedure Open(sWeb: string);
    { Public declarations }
  end;

var
  frmWebBrowser             : TfrmWebBrowser;

implementation

uses ClMain;

{$R *.dfm}

procedure TfrmWebBrowser.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then begin
    ReleaseCapture;
    Perform(WM_SYSCOMMAND, $F012, 0);
  end;
end;

procedure TfrmWebBrowser.Open(sWeb: string);
begin
  WebBrowser.Navigate(sWeb);
  Show;
end;

procedure TfrmWebBrowser.RzBmpButton1Click(Sender: TObject);
begin
  Close;
end;

//procedure SetWindowBackgroundImage(hWnd: HWND; const FileName: string);
//var
//  hBitmap: HBITMAP;
//begin
//  hBitmap := LoadImage(0, PChar(FileName), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
//  if hBitmap <> 0 then
//  begin
//    SendMessage(hWnd, WM_SETREDRAW, 0, 0);
//    SendMessage(hWnd, WM_SETTEXT, 0, 0);
//    SendMessage(hWnd, STM_SETIMAGE, IMAGE_BITMAP, hBitmap);
//    SendMessage(hWnd, WM_SETREDRAW, 1, 0);
//    RedrawWindow(hWnd, nil, 0, RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN);
//  end;
//end;

procedure TfrmWebBrowser.FormCreate(Sender: TObject);
begin
  Top := (SCREENHEIGHT - Height) div 2;
  Left := (SCREENWIDTH - Width) div 2;
  Windows.SetParent(Handle, FrmMain.Handle);
  BringToFront;
end;

procedure TfrmWebBrowser.WebBrowserDocumentComplete(ASender: TObject;
  const pDisp: IDispatch; const URL: OleVariant);
begin
  WebBrowser.OleObject.Document.Body.Scroll := 'no';
end;

procedure TfrmWebBrowser.WebBrowserNewWindow2(ASender: TObject; var ppDisp: IDispatch; var Cancel: WordBool);
var
  NewApp                    : TfrmWebBrowser;
begin
  NewApp := TfrmWebBrowser.Create(Self);
  NewApp.ParentWindow := frmWebBrowser.Handle;
  NewApp.Show;
  NewApp.SetFocus;
  ppDisp := NewApp.WebBrowser.Application;
end;

procedure TfrmWebBrowser.WebBrowserWindowClosing(ASender: TObject;
  IsChildWindow: WordBool; var Cancel: WordBool);
begin
  Cancel := True;
  Close;
end;

procedure TfrmWebBrowser.sbtnWebBrowserCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmWebBrowser.SpeedButton1Click(Sender: TObject);
begin
  WebBrowser.GoBack;
end;

procedure TfrmWebBrowser.SpeedButton2Click(Sender: TObject);
begin
  WebBrowser.GoForward;
end;

end.

